package gui.statistiche;

import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import javax.swing.BorderFactory;
import javax.swing.ImageIcon;

import javax.swing.JDesktopPane;
import javax.swing.WindowConstants;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

import org.h2.util.IntIntHashMap;

import db.CustomerDBInteraction;
import db.DBConnection;
import db.DBInteraction;
import db.ImpiantoDBInteraction;

/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class ShowStatisticheJPanel extends javax.swing.JPanel {
	private JPanel statistichejPanel;
	private JLabel logojLabel;
	private JLabel vTotaleClientijLabel;
	private JLabel vTotaleNuoviClientijLabel;
	private JLabel totaleNuoviClientijLabel;
	private JLabel vTotaleClientiAttivijLabel;
	private JLabel totaleClientiAttivijLabel;
	private JLabel vTotaleImpiantiProvinciajLabel;
	private JLabel vTotaleImpiantiCSjLabel;
	private JLabel vTotaleImpiantijLabel;
	private JLabel totaleImpiantiProvinciajLabel;
	private JLabel totaleImpiantiCSjLabel;
	private JLabel totaleImpiantijLabel;
	private JLabel totaleClientiJLabel;
	private JPanel logojPanel;
	
	private DBConnection dbCon;
	private JDesktopPane jDeskPane;
	private int totaleClienti, totaleImpianti, totaleImpiantiProvincia, totaleImpiantiCosenza, totaleClientiAttivi, totaleNuoviClienti;

	/**
	* Auto-generated main method to display this 
	* JPanel inside a new JFrame.
	*/
	public static void main(String[] args) {
		JFrame frame = new JFrame();
		frame.getContentPane().add(new ShowStatisticheJPanel());
		frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
		frame.pack();
		frame.setVisible(true);
	}
	
	public ShowStatisticheJPanel() {
		super();
		initGUI();
	}
	
	public ShowStatisticheJPanel(JDesktopPane jDeskPane, DBConnection dbCon) {
		super();
		this.jDeskPane = jDeskPane;
		this.dbCon = dbCon;
		initGUI();
		initFromDB();
	}
	
	private void initGUI() {
		try {
			this.setPreferredSize(new java.awt.Dimension(595, 363));
			{
				statistichejPanel = new JPanel();
				GridBagLayout statistichejPanelLayout = new GridBagLayout();
				this.add(statistichejPanel);
				statistichejPanel.setPreferredSize(new java.awt.Dimension(425, 151));
				statistichejPanel.setBorder(BorderFactory.createTitledBorder("Statistiche"));
				statistichejPanelLayout.rowWeights = new double[] {0.1, 0.1, 0.1, 0.1};
				statistichejPanelLayout.rowHeights = new int[] {7, 7, 7, 7};
				statistichejPanelLayout.columnWeights = new double[] {0.0, 0.1, 0.0, 0.1};
				statistichejPanelLayout.columnWidths = new int[] {152, 7, 177, 7};
				statistichejPanel.setLayout(statistichejPanelLayout);
				{
					totaleClientiJLabel = new JLabel();
					statistichejPanel.add(totaleClientiJLabel, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 10, 0, 0), 0, 0));
					totaleClientiJLabel.setText("Totale Clienti:");
					totaleClientiJLabel.setFont(new java.awt.Font("Segoe UI",3,12));
				}
				{
					totaleImpiantijLabel = new JLabel();
					statistichejPanel.add(totaleImpiantijLabel, new GridBagConstraints(2, 0, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 10, 0, 0), 0, 0));
					totaleImpiantijLabel.setText("Totale Impianti: ");
					totaleImpiantijLabel.setFont(new java.awt.Font("Segoe UI",3,12));
				}
				{
					totaleImpiantiCSjLabel = new JLabel();
					statistichejPanel.add(totaleImpiantiCSjLabel, new GridBagConstraints(2, 1, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 10, 0, 0), 0, 0));
					totaleImpiantiCSjLabel.setText("Totale Impianti Cosenza: ");
					totaleImpiantiCSjLabel.setFont(new java.awt.Font("Segoe UI",3,12));
				}
				{
					totaleImpiantiProvinciajLabel = new JLabel();
					statistichejPanel.add(totaleImpiantiProvinciajLabel, new GridBagConstraints(2, 2, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 10, 0, 0), 0, 0));
					totaleImpiantiProvinciajLabel.setText("Totale Impianti Provincia: ");
					totaleImpiantiProvinciajLabel.setFont(new java.awt.Font("Segoe UI",3,12));
				}
				{
					vTotaleClientijLabel = new JLabel();
					statistichejPanel.add(vTotaleClientijLabel, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
					vTotaleClientijLabel.setText("X");
					vTotaleClientijLabel.setFont(new java.awt.Font("Segoe UI",1,12));
				}
				{
					vTotaleImpiantijLabel = new JLabel();
					statistichejPanel.add(vTotaleImpiantijLabel, new GridBagConstraints(3, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
					vTotaleImpiantijLabel.setText("X");
					vTotaleImpiantijLabel.setFont(new java.awt.Font("Segoe UI",1,12));
				}
				{
					vTotaleImpiantiCSjLabel = new JLabel();
					statistichejPanel.add(vTotaleImpiantiCSjLabel, new GridBagConstraints(3, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
					vTotaleImpiantiCSjLabel.setText("X");
					vTotaleImpiantiCSjLabel.setFont(new java.awt.Font("Segoe UI",1,12));
				}
				{
					vTotaleImpiantiProvinciajLabel = new JLabel();
					statistichejPanel.add(vTotaleImpiantiProvinciajLabel, new GridBagConstraints(3, 2, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
					vTotaleImpiantiProvinciajLabel.setText("X");
					vTotaleImpiantiProvinciajLabel.setFont(new java.awt.Font("Segoe UI",1,12));
				}
				{
					totaleClientiAttivijLabel = new JLabel();
					statistichejPanel.add(totaleClientiAttivijLabel, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 10, 0, 0), 0, 0));
					totaleClientiAttivijLabel.setText("Clienti Attivi:");
					totaleClientiAttivijLabel.setFont(new java.awt.Font("Segoe UI",3,12));
				}
				{
					vTotaleClientiAttivijLabel = new JLabel();
					statistichejPanel.add(vTotaleClientiAttivijLabel, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
					vTotaleClientiAttivijLabel.setText("X");
					vTotaleClientiAttivijLabel.setFont(new java.awt.Font("Segoe UI",3,12));
				}
				{
					totaleNuoviClientijLabel = new JLabel();
					statistichejPanel.add(totaleNuoviClientijLabel, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 10, 0, 0), 0, 0));
					totaleNuoviClientijLabel.setText("Nuovi Clienti (Anno):");
					totaleNuoviClientijLabel.setFont(new java.awt.Font("Segoe UI",3,12));
				}
				{
					vTotaleNuoviClientijLabel = new JLabel();
					statistichejPanel.add(vTotaleNuoviClientijLabel, new GridBagConstraints(1, 2, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
					vTotaleNuoviClientijLabel.setText("X");
					vTotaleNuoviClientijLabel.setFont(new java.awt.Font("Segoe UI",3,12));
				}
			}
			{
				logojPanel = new JPanel();
				this.add(logojPanel);
				logojPanel.setPreferredSize(new java.awt.Dimension(137, 140));
				{
					logojLabel = new JLabel();
					logojPanel.add(logojLabel);
					logojLabel.setIcon(new ImageIcon(getClass().getClassLoader().getResource("images/icons/stats128.png")));
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	
	private void initFromDB()
	{
		this.totaleClienti = CustomerDBInteraction.getNumberOfCustomer(dbCon);
		vTotaleClientijLabel.setText("" + this.totaleClienti);
		this.totaleImpianti = ImpiantoDBInteraction.getNumberOfImpiantiTotali(dbCon);
		vTotaleImpiantijLabel.setText("" + this.totaleImpianti);
		this.totaleImpiantiCosenza = ImpiantoDBInteraction.getNumberOfImpiantiCosenza(dbCon);
		vTotaleImpiantiCSjLabel.setText("" + this.totaleImpiantiCosenza);
		this.totaleImpiantiProvincia = ImpiantoDBInteraction.getNumberOfImpiantiProvincia(dbCon);
		vTotaleImpiantiProvinciajLabel.setText("" + this.totaleImpiantiProvincia);
		this.totaleClientiAttivi = CustomerDBInteraction.getNumberOfActiveCustomers(dbCon);
		vTotaleClientiAttivijLabel.setText("" + this.totaleClientiAttivi);
		this.totaleNuoviClienti = CustomerDBInteraction.getNumberOfNewCustomers(dbCon);
		vTotaleNuoviClientijLabel.setText("" + this.totaleNuoviClienti);
	}
}
